<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="shortcut icon" href="#">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
    <meta charset="UTF-8">
    <title>owr.cc</title>
</head>
<body>
 <p id ='pbq' style="text-align: center;"></p>
  <h5 id ='h5bq' style="text-align: center;"></h5>
<div style="width: 80%;height: 100%;border: 1px solid #ccc;margin: 0 auto;">
    <div id="msg" style="width: 100%;height: 380px;text-align: center;overflow: auto;"></div>
    <div style="text-align: center;margin-bottom: 20px;">
        <input onkeydown='if(event.keyCode==13){send()}' style="width: 60%;height: 25px;" type="text" id="text" >
        <input id="fsan" type="submit" onclick="send();" style="height: 30px;" value="发送消息">
    </div>
</div>

<script src="index.js"></script>
<script>
    var flag = 1
    if (navigator.language =='zh-CN'){
        flag = 0
    }
    var yylb = {
        "ljts":['连接成功','connection succeeded!'],
        'fwqgbts':['服务器断开 刷新页面重新进入聊天','Server disconnected Refresh the page to re-enter the chat'],
        'pbq':['owr.cc 全球高匿聊天','owr.cc Global High Anonymous Chat'],
        'h5bq':['聊天过程一旦断开<br/>聊天记录无法恢复','Once the chat process is disconnected<br/>Chat history cannot be recovered'],
        'fsan':['发送消息','send']
    }
    pbq.innerHTML = yylb['pbq'][flag];
    h5bq.innerHTML = yylb['h5bq'][flag];
    fsan.value = yylb['fsan'][flag];
    var wsServer = "ws://127.0.0.1:444/"+flag; // 127.0.0.1改成你的公网ip 或者本地IP
    var webSocket = new WebSocket(wsServer);
    var msg = document.getElementById('msg');
    webSocket.onopen = function (res) {msg.innerHTML += yylb['ljts'][flag] + "<br>";}
    webSocket.onmessage = function (res) {
		let reader = new FileReader();
		reader.readAsArrayBuffer(res.data, "utf-8");
		reader.onload = function() {
			let msgdata = pako.inflate(reader.result, {
					to: "string"
				});
			msg.innerHTML += msgdata + "<br/>";
			document.getElementById('msg').scrollTop = document.getElementById('msg').scrollHeight
		};
    }
    webSocket.onclose = function (res) {
       msg.innerHTML += yylb['fwqgbts'][flag] + "<br>";
    }
    function send() {
        var text = document.getElementById('text').value;
        webSocket.send(pako.gzip(text));
        document.getElementById('text').value =''
    }
</script>
</body>
</html>